using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PersonDomain;
using ShivamEMR.Model.DataInterfaces.PersonDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;
//using ShivamEMR.Web.Areas.Person.Models;

namespace ShivamEMR.Web.Areas.Person.Controllers
{   
    public class PersonStatusController : Controller
    {
		private readonly IPersonStatusRepository personstatusRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PersonStatusController() 
        {
            personstatusRepository = Registry.RepositoryFactory.GetPersonStatusRepository();
        }

        public PersonStatusController(IPersonStatusRepository personstatusRepository)
        {
			this.personstatusRepository = personstatusRepository;
        }

        //
        // GET: /PersonStatus/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
            //return View(personstatusRepository.AllIncluding(personstatus => personstatus.Persons));
            return View(personstatusRepository.All);
        }

        //
        // GET: /PersonStatus/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(personstatusRepository.Find(id));
        }

        //
        // GET: /PersonStatus/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PersonStatus/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(PersonStatus personstatus)
        {
            if (ModelState.IsValid) {
                personstatusRepository.Create(personstatus);
                personstatusRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /PersonStatus/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
             return View(personstatusRepository.Find(id));
        }

        //
        // POST: /PersonStatus/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(PersonStatus personstatus)
        {
            if (ModelState.IsValid) {
                personstatusRepository.Update(personstatus);
                personstatusRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /PersonStatus/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(personstatusRepository.Find(id));
        }

        //
        // POST: /PersonStatus/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
           // personstatusRepository.Delete(id);
           var pstatus=  personstatusRepository.Find(id);
           personstatusRepository.Delete(pstatus);
            personstatusRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

